<template>
  <div class="collect" style="width:700px;">
    <div class="right_div_title">
      <p>我的收藏</p>
    </div>
    <div class="right_div_ct">
      <div class="right_div_tab">
        <ul>
          <li ref="ask" :class="type === 'ask' ? 'active':''" @click="active('ask')">问答
            <label>{{ qlist.length }}</label>
            <span />
          </li>
          <li ref="article" :class="type === 'article' ? 'active': ''" @click="active('article')">文章
            <label>{{ articleList.length }}</label>
            <span />
          </li>
        </ul>
      </div>
      <div class="tabContent">
        <ul class="ask" :class="type === 'ask' ? 'active' : ''">
          <li v-for="q in qlist" :key="q.question.id">
            <div class="answer_item_t">
              <router-link :to="{name: 'User', params: { id: q.question.userId } }">
                <el-avatar :src="q.questionerAvatar" class="img" />
              </router-link>
              <div class="answer_author">
                {{ q.questionerUsername }}
                <span>{{ parseTime(q.question.createTime) }}</span>
              </div>
              <div class="answer_num">{{ q.answerCount }} 个回答</div>
            </div>
            <div class="answer_title">
              <router-link :to="{name: 'QuestionDetail', params: { id: q.question.id } }">
                {{ q.question.title }}
              </router-link>
            </div>
            <div class="answer_text">
              <router-link :to="{name: 'QuestionDetail', params: { id: q.question.id } }">
                {{ q.question.content }}
              </router-link>
            </div>
          </li>
        </ul>
        <ul class="article" :class="type === 'article' ? 'active' : ''">
          <li v-for="article in articleList" :key="article.article.id">
            <a target="_blank">
              <el-image class="cover" />
            </a>
            <div class="article_r">
              <div class="article_title">
                <a target="_blank">{{ article.article.title }}</a>
              </div>
              <div class="article_desc">
                <a target="_blank">{{ article.article.description }}</a>
              </div>
              <div class="article_b">
                <ul>
                  <li class="article_time"> {{ article.article.createTime }}</li>
                  <li class="article_readCount">{{ article.readCount }} 阅读</li>
                </ul>
              </div>
            </div>
          </li>
        </ul>
        <div class="more_text">
          <span />
          更多内容 敬请期待
          <span />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getMyCollection } from '@/api/user'
import { collectionQuestion } from '@/api/question'
import { mapGetters } from 'vuex'
import { formatTime } from '@/utils/index'
export default {
  name: 'Collection',
  data() {
    return {
      type: '',
      articleList: [],
      qlist: []
    }
  },
  computed: {
    ...mapGetters([
      'user_id'
    ])
  },
  mounted() {
    this.type = 'ask'
    this.myCollectionArticle()
    this.collectionQuestion()
  },
  methods: {
    myCollectionArticle() {
      getMyCollection({ userId: this.$store.state.user.id }).then(res => {
        this.articleList = res.data
      })
    },
    collectionQuestion() {
      collectionQuestion({ userId: this.user_id }).then(res => {
        this.qlist = res.data
      })
    },
    parseTime(time) {
      return formatTime(new Date(time))
    },
    active(type) {
      this.type = type
    }
  }
}
</script>

<style lang="scss" scoped>
.collect{
  padding-bottom: 20px;
  height: auto;
}
li, ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.right_div_title p {
    height: 48px;
    width: 100%;
    line-height: 48px;
    font-size: 16px;
    color: #999;
    background: #fff;
    border-radius: 10px;
    text-indent: 30px;
}
.right_div_ct{
  background: #fff;
  border-radius: 10px;
}
.right_div_tab {
    height: 60px;
    line-height: 60px;
    border-bottom: 1px solid #f1f1f1;
}
.right_div_tab .active {
    font-weight: 700;
    color: #0b8bff;
}
.right_div_tab ul {
    overflow: auto;
    padding-left: 50px;
    li {
      position: relative;
      float: left;
      margin-right: 80px;
      font-size: 18px;
      color: #666;
      cursor: pointer;
    }
}
.right_div_tab ul li.active span {
    display: inline-block;
}
.right_div_tab ul li span {
    display: none;
    width: 42px;
    height: 2px;
    background: #0b8bff;
    border-radius: 18px;
    position: absolute;
    bottom: 0;
    right: 0;
    left: 0;
    margin: auto;
}
.tabContent ul {
    display: none;
    overflow: auto;
    padding: 0 30px;
    li {
      overflow: auto;
      padding: 30px 0;
    }
}
.tabContent ul.active {
    display: block;
}
.answer_item_t .img {
    float: left;
    height: 30px;
    width: 30px;
    background-position: 50%;
    background-repeat: no-repeat;
    background-size: cover;
    border-radius: 50%;
    overflow: hidden;
}
.ask li {
    border-bottom: 1px solid #f1f1f1;
}
a {
    text-decoration: none;
    color: inherit;
}
.tabContent ul li .answer_item_t {
    line-height: 30px;
    overflow: auto;
    .answer_cover {
      float: left;
      height: 30px;
      width: 30px;
      background-position: 50%;
      background-repeat: no-repeat;
      background-size: cover;
      border-radius: 50%;
      overflow: hidden;
    }
     .answer_author {
      float: left;
      margin-left: 20px;
      font-size: 16px;
      color: #333;
      font-weight: 700;
    }
}
.answer_author span {
    font-weight: 400;
    margin-left: 10px;
    font-size: 14px;
    color: #ccc;
}
.answer_num {
    float: right;
    font-size: 14px;
    color: #ccc;
}
.answer_title {
    margin: 18px 0 14px;
    font-size: 20px;
    color: #333;
    font-weight: 700;
}
.answer_title a:hover{
  color: #0b8bff;
}
.answer_text {
    font-size: 14px;
    color: #999;
    line-height: 22px;
    max-height: 66px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    word-break: break-all;
}
.more_text {
    width: 100%;
    height: auto;
    margin: 30px 0;
    font-size: 14px;
    text-align: center;
    color: #999;
    line-height: normal;
    span {
      display: inline-block;
      width: 6px;
      height: 6px;
      background: #999;
      margin: 0 10px;
      border-radius: 50%;
      vertical-align: middle;
    }
}
.tabContent .article li:last-of-type {
    border-bottom: 1px solid #f1f1f1;
}
.tabContent .article li:first-of-type {
    padding-top: 50px;
}
.cover {
    float: left;
    width: 98px;
    height: 98px;
    margin-right: 18px;
    overflow: hidden;
    cursor: pointer;
    background-size: cover;
    background-position: 50%;
    background-repeat: no-repeat;
}
.article_r {
    float: left;
    width: 516px;
    height: auto;
    .article_title {
        font-size: 20px;
        font-weight: 700;
        color: #333;
        line-height: 20px;
        cursor: pointer;
    }
    .article_desc {
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      overflow: hidden;
      margin-top: 12px;
      line-height: 20px;
      font-size: 14px;
      color: #666;
      cursor: pointer;
    }
    .article_b {
      margin-top: 8px;
      font-size: 14px;
      line-height: 20px;
      color: #999;
      overflow: auto;
    }
}
.article_b ul {
    display: block;
    overflow: auto;
    padding: 0;
}
.right_div_ct .tabContent ul li .article_r .article_b li {
    float: left;
    margin-right: 32px;
    padding: 0;
    border: none;
}
.right_div_ct .tabContent ul li .article_r .article_b li:last-of-type {
    float: right;
}

</style>
